<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%
chatManagers.DBMSManager dbm = new chatManagers.DBMSManager();

int cid = 0;
String chatID = "";        
String uName = request.getRemoteUser();

chatID = request.getParameter("chatid");
if(chatID!=null && !chatID.equals("")) {
	cid = new Integer(chatID).intValue();
}
        
try{
	if(dbm.isChatActive(cid) && dbm.checkLogin(uName)!=0) {
   		//We're cool
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chat Rooms</title>
<link rel="stylesheet" href="../default.css">
<link href="../includes/chat.css" rel="stylesheet" type="text/css" media="screen" />

<script type="text/javascript" src="../includes/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="../includes/common.js"></script>

<jsp:useBean id="ub" class="chatManagers.UserBean" scope="session" />
<jsp:setProperty name="ub" property="chatid" />
<jsp:setProperty name="ub" property="chatName" />
</head>

<body onload = "signOn(<jsp:getProperty name="ub" property="chatid" />,<jsp:getProperty name="ub" property="userid" />);" onUnload = "signOff()";>

        <div id="chatheader">
            <h1><jsp:getProperty name="ub" property="chatName" /></h1>
            <div id="header-left-col">
                <p>Active members of this chat are shown below in the list at the right. Use
                the button to the right to exit the chat and return to the WARE main site.</p>
            </div>
            <div id="header-right-col">
                <form action="#" id="soff" style="margin-bottom: 0px;">
                    <a href="javascript:signOff()"><img border="0" width="116" height="36" alt="Exit Chat" vspace="12" src="../img/chat_exit.gif"></a>&nbsp;
                    <a id="endchat" style="display:none;" href="javascript: endChat();" /><img border="0" width="113" height="36" alt="End Chat"  vspace="12" src="../img/chat_end.gif"></a>
                </form>
            </div>
        </div>
        
        <div id="chatbody">
            <div id="body-left-col">
                <div id="chat_contents"></div>
                <form action="#" id="commentfrm">
                    <h2>Add a comment</h2>
                    <input type="hidden" name="chatid" id="chatid" value='<jsp:getProperty name="ub" property="chatid" />' />
                    <input type="hidden" name="userid" id="userid" value='<jsp:getProperty name="ub" property="userid" />' />
                    <input type="hidden" name="doAction" id="doAction" value="signon" />
                    <input type="hidden" name="lastmsgid" id="lastmsgid" value="" />
                    <input type="hidden" name="startmsgid" id="startmsgid" value="" />
                    <textarea id="comment" name="comment" onkeypress="return event.keyCode!=13"></textarea>
                    <input type="button" name="sendbutton" id="sendbutton" value="Send" onClick="addComment()" />
                </form>
            </div>
            
            <div id="body-right-col">
                <form action="#" id="membersblock">
                    <h2>Members</h2>
                    <div id="members" class="side-block"> </div>
                </form>
                
                <form action="#" id="pvtmsgfrm">
                    <h2 id="pvtmsgheader">Send Private Message</h2>
                    <input type="hidden" name="pvtchatid" id="pvtchatid" value='<jsp:getProperty name="ub" property="chatid" />' />
                    <input type="hidden" name="pvtuserid" id="pvtuserid" value='<jsp:getProperty name="ub" property="userid" />' />
                    <input type="hidden" name="pvttargetid" id="pvttargetid" value="" />
                    <textarea id="pvtcomment" name="pvtcomment" rows="5" cols="30"></textarea><br />
                    <input type="button" value="Send Message" onmouseup="sendPvtMsg()" />
                    <input type="button" value="Close" onClick="toggleWindow(document.getElementById('pvtmsgfrm'))" />
                </form>
                
                <form action="#" id="pvtmessages" style="display: none;">
                    <h2>Private Messages</h2>
                    <div id="pvtmessage_contents"> </div>
                </form>
            </div>
        </div>

<br clear="all"/>
  
<hr><p align='center'>&copy; 2007 SIS<br>
Site maintained by <a href="mailto:spring@pitt.edu">MBSpring</a><br>
Phone</p>


</body>
</html>
<%
} else {
	response.sendRedirect("index.jsp");
}
            
} catch (Exception e) {
      e.printStackTrace();
} finally {
	dbm.closeConnection();
}

%>
